#include <csignal>
#include <iostream>
#include <string>
#include <list>
using std::list;
using std::string;
using std::cout;
using std::endl;

class student{
public:
    student(string name,float chinese,float math,float english)
    :_name(name)
    ,_chinese(chinese)
    ,_math(math)
    ,_english(english)
    {
        _sum = _chinese+_math+_english;
    }
    float chinese_score(){
        return _chinese;
    }
    float sum_score(){
        return _sum;
    }
    
    friend struct CompareList;
    friend std::ostream & operator<<(std::ostream & os, student & stu);
private:
    string _name;
    float _chinese;
    float _math;
    float _english;
    float _sum;
};

std::ostream & operator<<(std::ostream & os, student & stu){
    os << stu._name << " " << stu._sum << " " << stu._chinese;
    return os;
}

struct CompareList{
    bool operator()(const student& lhs,const student& rhs) const
    {
        cout << "struct CompareList" << endl;
        if(lhs._sum > rhs._sum){
            return true;
        }
        if(lhs._sum == rhs._sum && lhs._chinese >= rhs._chinese){
            return true;
        }
        return false;
    }
};

void test(){
    list<student> stu_list{
        student("xiongda",85,89,89),
        student("xionger",88,89,89),
        student("jjguowang",98,89,89),
        student("guangtq",90,99,87),
        student("qiuxiang",78,80,99)
    };
    stu_list.sort(CompareList());
    for(auto & temp:stu_list){
        cout << temp << endl;
    }

}

int main()
{
    

    test ();
    return 0;
}

